﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Common;

namespace EHR18
{
    public partial class EditReportColumnName : FrmBase
    {
      //  BindingList<KVMapping> _bindings = new BindingList<KVMapping>();
        public EditReportColumnName()
        {
            InitializeComponent();
          //  this.dataGridView1.DataSource = _bindings;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            GenneralConfig.instance.module.NameMappings = (dataGridView1.DataSource as BindingList<KVMapping>).ToList();
            GenneralConfig.instance.module.SerializeToXml(System.IO.Path.Combine("./Configs", GenneralConfig.instance.CurrentModel + ".xml"));
        }

        private void button2_Click(object sender, EventArgs e)
        {
            dataGridView1.DataSource = new BindingList<KVMapping>(GenneralConfig.instance.module.NameMappings);

        }

        private void button3_Click(object sender, EventArgs e)
        {
            var list = TBAllService.getNameStrings();
            List<KVMapping> _list = new List<KVMapping>();
            foreach (var a in list)
            {
                _list.Add(new KVMapping() { IsUse = true, Name = a, Value = a });
            }
                  this.dataGridView1.DataSource = new BindingList<KVMapping>(_list);
        //    _bindings = new BindingList<KVMapping>(_list);
            //    GenneralConfig.instance.module.SerializeToXml(System.IO.Path.Combine("./Configs", GenneralConfig.instance.CurrentModel + ".xml"));
        }

        private void EditReportColumnName_Load(object sender, EventArgs e)
        {

        }

        private void button4_Click(object sender, EventArgs e)
        {
            var list = TBAllService.getNameStrings();
            GenneralConfig.instance.module.ReportConfigItems.Clear();
            List<KVMapping> _list = new List<KVMapping>();
            foreach (var a in list.Where(t=>t.Contains(":Value")))
            {
                var name = a.Split(':')[1];
                GenneralConfig.instance.module.ReportConfigItems.Add(new ReportConfigItem() { Name = name });
                GenneralConfig.instance.SaveModuleConfig();
                _list.Add(new KVMapping() { IsUse = true, Name = name, Value = a });
            }
            this.dataGridView1.DataSource = new BindingList<KVMapping>(_list);
        }
    }
}

